local skel = fk.CreateSkill {
  name = "emo__nishi",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__nishi"] = "逆世",
  [":emo__nishi"] = "锁定技，每当你使用锦囊牌时，令你本回合手牌上限+1。当你连续使用两张锦囊牌时，令你下一张基本牌额外结算1次。当你连续使用三张锦囊牌时，摸一张牌。",

  ["@emo__nishi_basic"] = "逆世:额外结算",
}

skel:addEffect(fk.CardUsing, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and data.card.type == Card.TypeTrick
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn)
    local currentEvent = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if not currentEvent then return end
    -- 查询现在是连续第几次使用锦囊牌
    local n = 1
    local events = room.logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
    for i = #events, 1, -1 do
      local e = events[i]
      if e.id < currentEvent.id then
        local use = e.data
        if use.from == player then
          if use.card.type == Card.TypeTrick then
            n = n + 1
          else
            break
          end
        end
      end
    end
    if n > 1 then
      room:addPlayerMark(player, "@emo__nishi_basic")
    end
    if n > 2 then
      player:drawCards(1, skel.name)
    end
  end,

  --- 直接写这里没事吧
  can_refresh = function (self, event, target, player, data)
   return player == target and data.card.type == Card.TypeBasic and player:getMark("@emo__nishi_basic") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    data.additionalEffect = (data.additionalEffect or 0) + player:getMark("@emo__nishi_basic")
    player.room:setPlayerMark(player, "@emo__nishi_basic", 0)
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@emo__nishi_basic", 0)
end)

return skel
